package com.krdz.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import com.krdz.bean.PersonBean;
import com.krdz.service.PersonService;
/**
 * 人员管理控制器类
 * @author dinghao
 *
 * @date  2018年11月15日
 */
@Controller
@RequestMapping("person")
public class PersonController {
	
	@Resource
	private PersonService personService;
	
	//获取人员信息
	@RequestMapping(value="/findPersonInfo",produces="application/json;charset=UTF-8")
	@ResponseBody	
	public String getPersonInfo(PersonBean person){
		List<PersonBean> li=personService.findPersonInfo(person);
		String json= JSONObject.toJSONString(li);
		return json;
	}
	
	//添加人员信息
	@RequestMapping(value="/insertPerson",produces="application/json;charset=UTF-8")
	@ResponseBody	
	public String insertPerson(PersonBean person){
		if(personService.insertPerson(person)){
			return "success";
		}else{
			return "error";
		}
	
	}
	//删除人员信息
	@RequestMapping(value="/deletePerson",produces="application/json;charset=UTF-8")
	@ResponseBody	
	public String deletePerson(@RequestParam("id")Integer id){
		if(personService.deletePerson(id)){
			return "success";
		}else{
			return "error";
		}
	}
	
	//修改人员信息
	@RequestMapping(value="/updatePerson",produces="application/json;charset=UTF-8")
	@ResponseBody	
	public String updatePerson(PersonBean person){
		if(personService.updatePerson(person)){
			return "success";
		}else{
			return "error";
		}
	}
	
	//获取人员总记录数
	@RequestMapping(value="/getPersonCount",produces="application/json;charset=UTF-8")
	@ResponseBody	
	public String getPersonCount(){
		Integer count=personService.findPersonCount();
		
		return count.toString();
	}
}
